Chris Pollett > Old Classses >
CS174

( Print View )

Student Corner:
  [Grades Sec1]

  [Submit Sec1]

  [
Lecture Notes]
  [Discussion Board]

Course Info:
  [Texts & Links]
  [Description]
  [Course Outcomes]
  [Outcomes Matrix]
  [Course Schedule]
  [Grading]
  [Requirements/HW/Quizzes]
  [Class Protocols]
  [Exam Info]
  [Regrades]
  [University Policies]
  [Announcements]

HW Assignments:
  [Hw1]  [Hw2]  [Hw3]
  [Hw4]  [Hw5]  [Quizzes]

Practice Exams:
  [Midterm]  [Final]

                           












HW#2 --- last modified February 06 2019 04:11:56..

Solution set.

Due date: Mar 11

Files to be submitted:
  Hw2.zip

Purpose: To write a server-side application using PHP.

Related Course Outcomes:

The main course outcomes covered by this assignment are:

CLO1 -- Write HTML documents containing standard HTML elements including forms, tables, client-side scripts, and server-side scripts.

CLO1 -- Write server-side scripts that process HTML forms.

Specification:

Web analytics has been an important part of running a web-site since the days of web page counters in the 1990s. Two common approaches are to analyze server logs or to use page tagging. In log analytics, the web server log files are scanned and information about which ip addresses requests were made from, which pages were requested and the times of day and which day, are extracted. In page tagging, an image or a script is added to web pages and whenever that script is requested by a browser, the download of the image or the execution of the script is recorded. Log scanning has the advantages that it works for all file types, not just html pages, and can also estimated web crawler tracker; page tracking has the advantages that you can get a third party to handle your analytics for you and you can better track human engagement with a page. Neither of these analytics systems is particularly real time. For this homework, I'd like you to make a simple "integrated analytics" tool that can be used to track page hits and web traffic as it happens in real time. By "integrated" here I a mean it is integrated as part of your site.

Your tool will monitor traffic to the ./web-site subfolder of your project. Populate this folder with some simple dummy pages "1.html", "1.jpg", "2.html", "2.jpg", ... "10.html", "10.jpg" of file sizes between 5 and 10 kilobytes. In this folder also have a script, index.php. When you make a request:

http://your-project-domain/your-project-path/web-site/index.php/any-random-string

PHP will automatically set up the PATH_INFO and PATH_TRANSLATED fields for the $_SERVER super global with "/any-random-string" and the path to that file on the server if it exists. Using URL rewriting we could imagine making the index.php script not a part of the path, but for this homework, you can leave it. Using this information, your index.php script should output a header for the Content-Type of the file requested, then use readfile to serve that file, and finally, your script should update the data in a file counts.txt in the ./data subfolder of your whole project to record analytics. How you record data into counts.txt files I'll leave up to you, but it will be constrained by the second part of your project which is a site traffic monitoring page.

If a user to your site visits:

http://your-project-domain/your-project-path/analytics/index.php

They should be greeted with a page that says "Web-site Analytics" in an h1 tag and centered beneath there should be a form consisting of a labeled single drop down where the user can select between traffic for the last 10 seconds, last minute, last hour, or all time. Next to the drop down there should be a button with the word "Go" on it. Submitting this form, changes the data that is displayed beneath the form (when one first comes to the site we pretend as if the user had selected all time). This data should consist of two bar graphs. The first has headings which are the page names of web pages requested, followed by number of times downloaded in the interval selected on the form, followed by a bar whose length is proportional to the number of times the page was downloaded. These rows should be output sorted from largest to least counts. The second graph should have one row per ip address that visited your site in the interval selected on the form. These rows should also have counts, and a bar of length proportional to the counts. To implement the "bars" in the above, I want you to use CSS (don't use the canvas tag or images) applied to the background color of some tag. All CSS other than maybe inline styles for the width of these bars should be in a file ./analytics/site.css. Your page should have on it a meta refresh tag so that it reloads every 20 seconds. The coding of your php files should be nicely split into functions and should try to follow the model-view-adapter design pattern we discuss in class.

Point Breakdown

All web pages output validate as HTML 5 and pass the WAVE accessibility tool tests. 1pt
./web-site/index.php serves pages in the ./web-site folder as described. 1pt
./web-site/index.php updates page request info in ./data/counts.txt 1pt
Header and form on ./analytics/index.php page as described. 1pt
Page draws two bar graphs as described 1pt
Bars are created as described using style directives in ./analytics/site.css, no in-line styles used on any pages 1pt
Each Bar graph accurately reflects the traffic its responsible for for the time period chosen (1pt each) 2pts
Page has meta refresh tag as described 1pt
PHP files nicely split into functions and use model view adapter architecture described in class. 1pt
Total10pts